<?php
defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' );
class Index_admin extends CI_Controller {
	public function __construct() {
		parent::__construct ();
	}
	/*
	 * 跳转到后台主页，如果未登录，跳转到登陆页面
	 */
	public function index() {
		if (! $this->session->userdata ( 'logged_in' )) {
			redirect ( 'index_admin/login' );
			exit ();
		}
		$data ['title'] = '回扣管理系统';
		$this->load->view ( 'header', $data );
		$this->load->view ( 'index' );
		$this->load->view ( 'footer' );
	}
	/*
	 * 跳转到登陆页面
	 */
	public function login() {
		$this->load->view ( 'login' );
		//$this->load->view ( 'footer' );
	}
	/*
	 * 登陆验证
	 */
	public function signin() {
		$username = $this->input->post ( 'username' );
		$password = $this->input->post ( 'password' );
		
		$this->load->model ( 'admin_model' );
		
		if ($admin = $this->admin_model->get_admin ( $username, md5($password.'jishibao')) ){
			if($admin['type']!=1&&$admin['type']!=7){
				return_json(FALSE,'','没有权限！'); 
			}
			$admins = array (
					'id' => $admin ['id'],
					'name' => $admin ['username'],
					'type'=> $admin['type'],
					'logged_in' => TRUE 
			);
			$this->session->set_userdata ( $admins );
			
			return_json(TRUE,'','登陆成功！'); 
		} else {
			return_json(FALSE,'','用户名或密码错误！'); 
		}
	}
	/*
	 * 注销
	 */
	public function logout(){
		$this->session->sess_destroy();
		redirect('index_admin/login');
	}
}
